package com.youdianda.controller;


import com.youdianda.dto.ArticleDto;
import com.youdianda.dto.ArticlePageDto;
import com.youdianda.dto.RegDto;
import com.youdianda.result.Result;
import com.youdianda.service.IYddArticleService;
import com.youdianda.service.IYddUserService;
import com.youdianda.service.IndexService;
import com.youdianda.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("userIndexController")
@RequestMapping("/index")
public class IndexController {
    @Autowired
    IndexService indexService;

    @Autowired
    private IYddArticleService iYddArticleService;
    @Autowired
    private IYddUserService iYddUserService;



    @GetMapping("/index")
    public Result index(){
        return indexService.index();
    }

    @GetMapping("show")
    public Result show(Integer id){
        return indexService.show(id);
    }

    @GetMapping("/recommend")
    public Result recommend(){
        return indexService.recommend();
    }


    /**
     * 查询热门文章
     * @param articlePageDto
     * @return
     */
    @GetMapping("/new")
    public Result<YddArticleVo> getNew(ArticlePageDto articlePageDto){
        // log.error("查询热门文章：{}", articlePageDto);
        YddArticleVo yddArticleVo= iYddArticleService.getArticle(articlePageDto);
        //log.error("查询数据：{}",articlePageDto);
        return Result.success(yddArticleVo);
    }

    @GetMapping("/list")
    public Result<ListVo> getList(ArticleDto articleDto){
        ListVo ListVo = iYddArticleService.getArticleList(articleDto);
        return Result.success(ListVo);

    }



    /**
     * 注册
     * @param regDto
     * @return
     */
    @PostMapping("/reg")
    public Result<YddUserVO> reg(@RequestBody RegDto regDto){
        YddUserVO yddUserVo= iYddUserService.reg(regDto);
        return Result.success(yddUserVo);

    }

    /**
     * 最新文章
     * @return
     */
    @GetMapping("/hot")
    public Result<YddArticleHotVo> getnew(){
        YddArticleHotVo hot = iYddArticleService.getNew();
        return Result.success(hot);

    }

//    /**
//     * 推荐文章
//     * @return
//     */
//    @GetMapping("/recommend")
//    public Result<YddArticleHotVo>getRecommend(){
//        YddArticleHotVo hot = iYddArticleService.getArticleHot();
//        return Result.success(hot);
//
//    }
//
//    /**
//     * 首页和全局数据
//     * @return
//     */
//    @GetMapping("/index")
//    public Result<ArticleIndexVo> getIndex(){
//        ArticleIndexVo articleIndexVo= iYddArticleService.getIndex();
//        return Result.success(articleIndexVo);
//
//    }

//    @GetMapping("show")
//    public Result<ShowVo> show(Integer id){
//        ShowVo showVo= iYddArticleService.getShow(id);
//        return Result.success(showVo);
//
//    }

}
